package com.apes.scm.masterdata.stock.repository;

import com.apes.framework.jpa.repository.CustomRepository;
import com.apes.scm.masterdata.stock.model.Depot;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author xul
 * @create 2018-01-23 16:07
 */
public interface DepotRepository extends CustomRepository<Depot, String> {

    @Query("SELECT T FROM Depot T WHERE 1 = 1 and (id like %:value% or name like %:value%) ")
    Page<Depot> find( @Param("value") String value, Pageable pageable);

    @Query(value = "" +
            "SELECT A.*, B.ID LOCATION_ID, B.NAME LOCATION_NAME " +
            "  FROM MAS_DEPOT A, MAS_LOCATION B " +
            " WHERE A.ID = B.DEPOT_ID " +
            "   AND B.USAGE_ID = '1' " +
            "   AND A.LAST_UPDATED_STAMP > ?1 ", nativeQuery = true)
    List<Map> findDepotApp(Date times, Pageable pageable);
}
